import {
  addMaterialLibraryItemApi, deleteMaterialLibraryItemApi,
  getMaterialLibraryDataApi,
  getMaterialRepositoryListApi, queryMaterialLibraryListApi, updateMaterialLibraryItemApi
} from "../../../util/request/materialLibraryApi";

class MaterialLibraryManager{
  parseExcel(file){
    let formData = new FormData();
    formData.append('file',file.raw);
    getMaterialRepositoryListApi(formData).then(res=>{
      console.log(res);
    })
  }
  getMaterialLibraryData(cb){
    getMaterialLibraryDataApi().then(res=>{
      if(res?.status === 200){
        cb(res.data)
      }
    })
  }
  addMaterialLibraryItem(params,cb){
    let formData = new FormData();
    formData.append('number',params.number ?? "");
    formData.append('name',params.name ?? "");
    formData.append('level',params.level ?? "");
    formData.append('area',params.area ?? "");
    formData.append('density',params.density ?? "");
    formData.append('standard',params.standard ?? "");
    formData.append('unit',params.unit ?? "");
    formData.append('layer',params.layer ?? "");
    addMaterialLibraryItemApi(formData).then(res=>{
      if(res?.status === 200){
        cb(res.data)
      }
    })
  }
  deleteMaterialLibraryItem(params,cb){
    let formData = new FormData();
    formData.append('id',params);
    deleteMaterialLibraryItemApi(formData).then(res=>{
      if(res?.status === 200){
        cb(res.data)
      }
    })
  }
  updateMaterialLibraryItem(params,cb){
    let formData = new FormData();
    formData.append('id',params.id ?? "");
    formData.append('number',params.number ?? "");
    formData.append('name',params.name ?? "");
    formData.append('level',params.level ?? "");
    formData.append('area',params.area ?? "");
    formData.append('density',params.density ?? "");
    formData.append('standard',params.standard ?? "");
    formData.append('unit',params.unit ?? "");
    formData.append('layer',params.layer ?? "");
    updateMaterialLibraryItemApi(formData).then(res=>{
      if(res?.status === 200){
        cb(res.data)
      }
    })
  }
  queryMaterialLibraryList(keyWords,cb){
    queryMaterialLibraryListApi(keyWords).then(res=>{
      if(res?.status === 200){
        cb(res.data)
      }
    })
  }
}
const materialLibraryManager = new MaterialLibraryManager();
export { materialLibraryManager };